/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * LogoPanel.java
 *
 * Created on 24-lug-2009, 17.29.58
 */

package tr3dtris.game.display.ui;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

/**
 *
 * @author Luciano
 */
public class LogoPanel extends javax.swing.JPanel {
    private static final String LOGOFILE = "res/logo.png";
    private static final String LOGOSMALLFILE = "res/logosmall.png";
    private BufferedImage logo;
    private boolean scaleLogo;

    /** Creates new form LogoPanel */
    public LogoPanel()
    {
        this(true);
    }
    
    
    public LogoPanel(boolean scaleLogo) {
        this.scaleLogo = scaleLogo;
        try {
          String file = LOGOSMALLFILE;
          if (scaleLogo)
              file = LOGOFILE;

          this.logo = ImageIO.read(new File(file));
       } catch (IOException ex) {
          this.logo = null;
          ex.printStackTrace();
       }
        initComponents();
    }

    @Override
    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        if(this.logo != null)
        {   
            int imOrigWidth = logo.getWidth();
            int imOrigHeight = logo.getHeight();
            int panWidth = this.getWidth();
            int panHeight = this.getHeight();
            int x,y,width,height;

            width = imOrigWidth;
            height = imOrigHeight;
            
            if(scaleLogo)
            {
                width = (int)(panWidth/100f*70);
                height = imOrigHeight * width / imOrigWidth;
            }
            
            x = panWidth/2 - width/2;
            y = panHeight/2 - height/2;

            g.drawImage(logo, x, y, width, height, null);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
